﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Dapper.Core;
using System.Web.SessionState;

namespace Dapper.Web.Admin.Handle
{
    /// <summary>
    /// 处理用户登录
    /// </summary>
    public class Login : IHttpHandler, IRequiresSessionState 
    {

        public void ProcessRequest(HttpContext context)
        {
            string userName = context.Request["userName"];
            //context.Request.QueryString["userName"]
            string passWord = context.Request.Form["password"];
            string ReturnUrl = context.Request.Form["ReturnUrl"];
            Dictionary<string, object> jsonDics = new Dictionary<string, object>();
            
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(passWord))
            {
                jsonDics.Add("result", "null");
            }
            else
            {
                Modle.User user;
                try
                {
                    user = Logic.LogicService.IUserLogicService.Login(userName, passWord);
                    if (null != user)
                    {
                        jsonDics.Add("result", "true");
                        jsonDics.Add("ReturnUrl", ReturnUrl);
                    }
                    else
                    {
                        jsonDics.Add("result", "false");
                    }
                    
                }
                catch
                {
                    jsonDics.Add("result", "false");
                }
            }
            string u = Json.Encode(jsonDics);
            context.Response.Write(Json.Encode(jsonDics));

          
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}